CLOUDMADE_URL=${CLOUDMADE_URL:=http://downloads.cloudmade.com/north_america/united_states/oregon/oregon.shapefiles.zip}
ZILLOW_URL=${ZILLOW_URL:=http://www.zillow.com/static/shp/ZillowNeighborhoods-OR.zip}

CLOUDMADE_FILE=cloudmade.zip
ZILLOW_FILE=zillow.zip

SHP_FILES="administrative highway poi neighborhoods"
PG_USER=postgres
PG_DB=postgres
PROJ=4326

# grab the zip file
mkdir tmp
cd tmp

# 
# params: $1 = url, $2 = file
# wget $1 then unzip $2
#
function getShpZip {
    wget $1 -O $2
    unzip -L -o $2
}

#getShpZip $ZILLOW_URL $ZILLOW_FILE
#getShpZip $CLOUDMADE_URL $CLOUDMADE_FILE

for x in $SHP_FILES
do
    echo $x
    shp2pgsql -a -s $PROJ -W "ISO-8859-1" *$x*.shp $x > $x.csv
    psql -U $PG_USER -d $PG_DB -f ../load/$x.sql
    psql -U $PG_USER -d $PG_DB -f $x.csv
done
